package com.activity.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.activity.App;
import com.activity.BriefActivity;
import com.activity.CategoryActivity;
import com.activity.CategoryListActivity;
import com.activity.PersonInfoActivity;
import com.activity.SubCategoryListActivity;
import com.activity.bean.CategoryBean;
import com.activity.bean.OpusBean;
import com.activity.bean.UserBean;
import com.baoyz.actionsheet.ActionSheet;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.donkingliang.groupedadapter.holder.BaseViewHolder;
import com.example.apple.ddhr_new.R;
import com.example.apple.ddhr_new.activity.widget.BLinearLayout;
import com.example.apple.ddhr_new.adapter.BaseAdapter;
import com.example.apple.ddhr_new.utils.ActivityUtil;
import com.example.apple.ddhr_new.utils.ImageViewUtil;
import com.example.apple.ddhr_new.utils.ScreenUtil;
import com.example.lzbase.BaseActivity;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import co.lujun.androidtagview.TagContainerLayout;
import co.lujun.androidtagview.TagView;

public class CategoryListAdapter extends BaseAdapter<OpusBean> {


    public PersonAdapter.personListener personListener;
    public String id;

    public CategoryListAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder<OpusBean> getViewHolder(int viewType, View view) {
        if(viewType==TYPE_HEADER)
            return new PersonHeaderHolder(view);
        return new PersonalHolder(view);
    }
   public class PersonHeaderHolder extends BaseViewHolder<OpusBean> {



       @BindView(R.id.tagcontainerLayout2)
       TagContainerLayout tagcontainerLayout2;
        public PersonHeaderHolder(@NonNull View itemView) {
            super(itemView);

        }


        public void setData(OpusBean opusBean) {




            tagcontainerLayout2.setTags(tag);





        }

    }
    public ArrayList<CategoryBean> categorys = new ArrayList<>();
    public ArrayList<String> tag = new ArrayList<>();
    @Override
    public boolean hasHeader(int groupPosition) {
        return  true;
    }

    @Override
    public int getHeaderLayout(int viewType) {
        return R.layout.layout_header_category;
    }

    @Override
    public int getHeaderViewType(int groupPosition) {
        return TYPE_HEADER;
    }

    @Override
    public int getChildViewType(int groupPosition, int childPosition) {
        return TYPE_CHILD;
    }

    @Override
    public int getChildLayout(int viewType) {
        return R.layout.item_sub_personal_cell;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == TYPE_CHILD) {


            View view = LayoutInflater.from(mContext).inflate(getChildLayout(viewType), parent, false);

            return new PersonalHolder(view);

        } else if (viewType == TYPE_HEADER) {
            View view = LayoutInflater.from(mContext).inflate(getHeaderLayout(viewType), parent, false);

            return new PersonHeaderHolder(view);
        } else
            return super.onCreateViewHolder(parent, viewType);
    }

    @Override
    public void onBindChildViewHolder(com.donkingliang.groupedadapter.holder.BaseViewHolder holder, int groupPosition, int childPosition) {
        super.onBindChildViewHolder(holder, groupPosition, childPosition);

//        ((PersonalHolder) holder).iv_praise.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//                if(personListener!=null){
//                    personListener.praiseClick(childPosition);
//                }
//
//            }
//        });

    }

    @Override
    public void onBindHeaderViewHolder(com.donkingliang.groupedadapter.holder.BaseViewHolder holder, int groupPosition) {
        PersonHeaderHolder personHeaderHolder = (PersonHeaderHolder) holder;

        personHeaderHolder.setData(null);


        personHeaderHolder.tagcontainerLayout2.setOnTagClickListener(new TagView.OnTagClickListener() {
            @Override
            public void onTagClick(int position, String text) {

                if(position==tag.size()-1){
                    Bundle param =new Bundle();
                    param.putBoolean("param",true);
                    param.putString("super",id);
                    ActivityUtil.startActivity(mContext, CategoryActivity.class,param);
                }else {

                    Bundle param =new Bundle();
                    param.putString("name",categorys.get(position).getWorkscategoryname());
                    param.putString("id",categorys.get(position).getWorkscategoryid());
                    ActivityUtil.startActivity(mContext, SubCategoryListActivity.class,param);
                }
            }

            @Override
            public void onTagLongClick(int position, String text) {

            }

            @Override
            public void onSelectedTagDrag(int position, String text) {

            }

            @Override
            public void onTagCrossClick(int position) {

            }
        });
    }

    public class PersonalHolder extends BaseViewHolder<OpusBean> {
//        @BindView(R.id.iv_dianzan)
//        ImageView iv_praise;
        @BindView(R.id.iv_icon)
        ImageView ivIcon;
//        @BindView(R.id.tv_content)
//        TextView tvContent;
//        @BindView(R.id.iv_user_icon)
//        ImageView ivUserIcon;
//        @BindView(R.id.tv_name)
//        TextView tvName;
//        @BindView(R.id.tv_num)
//        TextView tvNum;

        public PersonalHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        public void setData(OpusBean data) {

            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) ivIcon.getLayoutParams();


//            WindowManager m = ((Activity) mContext).getWindowManager();
//            Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
//            params.width = (d.getWidth() - ScreenUtil.dp2px(mContext, 12)) / 2;
////            if (data.images().size() > 0) {
////                ImageViewUtil.loadImageCorner(data.images().get(0), ivIcon, mContext,R.drawable.meinv);
////            } else {
////                ivIcon.setImageResource(R.drawable.meinv);
////            }
//
//            if (data.getWorkssizes() != null) {
//                ArrayList<String> sizes = new ArrayList<String>(Arrays.asList(StringUtils.split(data.getWorkssizes(), "|")));
//
//                if (sizes.size() > 0) {
//                    ArrayList<String> size1 = new ArrayList<String>(Arrays.asList(StringUtils.split(sizes.get(0), ",")));
//                    params.height = (int) (params.width * Float.valueOf(size1.get(1)) / Float.valueOf(size1.get(0)));
//                    ivIcon.setLayoutParams(params);
//
//                } else {
//                    params.height = params.width;
//                    ivIcon.setLayoutParams(params);
//                }
//            } else {
//                params.height = params.width;
//                ivIcon.setLayoutParams(params);
//            }


            if (data.images().size() > 0) {

//                RoundedCorners roundedCorners = new RoundedCorners(10);
//                RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(300, 300);
//                options.placeholder(R.drawable.default_work);
//                Glide.with(mContext).load(data.images().get(0)).apply(options).into(ivIcon);
                RequestOptions options =new RequestOptions();

//                RoundedCorners roundedCorners = new RoundedCorners(0);
                options = options.override(300,300);
                options.placeholder(R.drawable.default_work);
                Glide.with(mContext).load(data.images().get(0)).apply(options).into(ivIcon);

            } else {
                ivIcon.setImageResource(R.drawable.meinv);
            }


//            tvName.setText(data.getUsernickname());
//            tvContent.setText(data.getWorkstitle());
//            tvNum.setText(data.getWorkspraisenum());
//
//            if(data.getWorkifpraise()!=null&&data.getWorkifpraise().equals("1")) {
//                iv_praise.setImageResource(R.drawable.dianzan1);
//            }else {
//                iv_praise.setImageResource(R.drawable.dianzan);
//            }
//            ImageViewUtil.loadCircleImage(data.getUsericon(), ivUserIcon, mContext);


        }


    }


}
